<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <base href="<%=basePath%>">
    <title>用户详情</title>
    <jsp:include page="/resources/v2/webui.jsp">
        <jsp:param name="UIS" value="FORM_LAYER_BTN_LAYOUT"/>
    </jsp:include>
</head>
<body>
<div class="tdh_layout" style="padding: 50px 0;">
    <div class="tdh_layout_t" style="height: 50px">
        <div class="tdh_form_title">用户管理</div>
    </div>
    <div class="tdh_layout_c" style="overflow: auto; padding: 5px">
        <table class="tdh_form" style="table-layout: fixed" method = "post">
            <colgroup>
                <col width="20%" />
                <col width="30%" />
                <col width="20%" />
                <col width="30%" />
            </colgroup>
            <tr>
                <td class="tdTitle"><i class="required">*</i>用户代码</td>
                <td class="tdCont"><input class="inputText need" type="text" data-name="用户代码"  name = "id" value="${user.yhdm}"/></td>

                <td class="tdTitle"><i class="required">*</i>ID</td>
                <td class="tdCont"><input class="inputText need" type="text" data-name="ID"  name = "userId"  value="${user.yhid}"/></td>
            </tr>
            <tr>
                <td class="tdTitle"><i class="required">*</i>姓名</td>
                <td class="tdCont"><input class="inputText need" type="text" data-name="姓名"  name = "username" value="${user.yhxm}"/></td>
                <td class="tdTitle">出生日期</td>
                <td class="tdCont"><input class="Wdate inputText" type="text" onclick="WdatePicker()" name='date'  value="${user.csrq}"/></td>
            </tr>
            <tr>
                <td class="tdTitle"><i class="required">*</i>密码</td>
                <td class="tdCont"><input class="inputText need" type="password" data-name="密码" name='password'  value="${user.yhkl}"/></td>
                <td class="tdTitle"><i class="required">*</i>确认密码</td>
                <td class="tdCont"><input class="inputText need" type="password" data-name="确认密码" name='passwordSure'  value="${user.yhkl}"/></td>

            </tr>
            <tr>
                <td class="tdTitle"><i class="required">*</i>性别</td>
                <td class="tdCont">
                    <select id="sex" name="sex" data-name="性别" class="inputSel">
                        <c:forEach var="sex"  items="${sexList}">
                            <option value="${sex.code}">${sex.mc}</option>
                        </c:forEach>
                    </select>
                </td>
                <td class="tdTitle"><i class="required">*</i>部门</td>
                <td class="tdCont">
                    <select  id="depart" name="depart" data-name="部门" class="inputSel" >
                        <c:forEach var="depart" items="${departList}">
                            <option value="${depart.bmdm}">${depart.bmmc}</option>
                        </c:forEach>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="tdTitle">是否禁用</td>
                <td class="tdCont">
                    <label><input class="inputRadio" type="radio" name="sfjy" value="1" />是</label>
                    <label><input class="inputRadio" type="radio" name="sfjy" value="0" checked/>否</label>
                </td>
                <td class="tdTitle">排序号</td>
                <td class="tdCont"><input class="inputText"  name='sortNum'  value="${user.pxh}"/></td>
            </tr>
        </table>
    </div>
    <div class="tdh_layout_b" style="height: 40px; text-align: center">
        <a class="tdh_btn tdh_btn_blue"  onclick="save()">
            <i class="tdh_icon icon_save" ></i>保存
        </a>
        <a class="tdh_btn tdh_btn_blue" onclick="closeWindow()">
            <i class="tdh_icon icon_return"></i>关闭
        </a>
    </div>
</div>
<script >
    function save() {
        var sortNum = $("input[name='sortNum']").val();
        var id = $("input[name='id']").val();
        var username = $("input[name='username']").val();
        var userId = $("input[name='userId']").val();
        var password = $("input[name='password']").val();
        var passwordSure = $("input[name='passwordSure']").val();
        var date = $("input[name='date']").val();
        var sex = $('#sex option:selected').val();
        var depart = $('#depart option:selected').val();
        var message="";
        $(".need").each(function (){
            if(!$(this).val()){
                message +=  " "+$(this).attr("data-name");
            }
        });
        var type1 = <%=request.getAttribute("type")%>;
        if(type1 == 0){
            $(".icon_save").toggle();
        };
        if (message) {
            layer.msg("请检查必填项！"+message.substring(), {
                icon: 2,
                shade: 0.000001, //不展示遮罩，但是要有遮罩效果
                time: 2000
            });
        }
        else if(passwordSure == '' || password != passwordSure){
            layer.msg("用户口令不一致！", {
                icon: 2,
                shade: 0.000001, //不展示遮罩，但是要有遮罩效果
                time: 2000
            });
        } else {
            var data = {
                "id":id,
                "sortNum":sortNum,
                "userId":userId,
                "password":password,
                "username":username,
                "date":date,
                "sex":sex,
                "depart":depart,
            }
            $.ajax({
                type: 'POST',
                url: "/user/save",
                data: data,
                dataType: "json",
                success: function (res) {
                    var res = eval(res);
                    if (1 == res) {
                        layer.msg("保存成功", {
                            icon: 1,
                            shade: 0.000001,
                            time: 2000
                        }, function (){
                            parent.layer.closeAll();
                        }
                            )
                    }else {
                        layer.msg("用户已存在！", {
                            icon: 2,
                            shade: 0.000001, //不展示遮罩，但是要有遮罩效果
                            time: 2000
                        });
                    }
                },

            })
        }

    }
    function closeWindow() {
        parent.layer.closeAll();
    }
</script>

</body>
</html>
